﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Lawyer.DAL
{
	/// <summary>
	/// 数据访问类:FileInfo
	/// </summary>
	public partial class FileInfo
	{
		public FileInfo()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string FileID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from FileInfo");
			strSql.Append(" where FileID=@FileID ");
			SqlParameter[] parameters = {
					new SqlParameter("@FileID", SqlDbType.VarChar,36)};
			parameters[0].Value = FileID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Lawyer.Model.FileInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into FileInfo(");
			strSql.Append("FileID,FileName,FileNote,FileURL,LawyerID,ArchiveID,IsArchive,CreatedBy,CreatedDate)");
			strSql.Append(" values (");
			strSql.Append("@FileID,@FileName,@FileNote,@FileURL,@LawyerID,@ArchiveID,@IsArchive,@CreatedBy,@CreatedDate)");
			SqlParameter[] parameters = {
					new SqlParameter("@FileID", SqlDbType.VarChar,36),
					new SqlParameter("@FileName", SqlDbType.VarChar,50),
					new SqlParameter("@FileNote", SqlDbType.VarChar,1000),
					new SqlParameter("@FileURL", SqlDbType.VarChar,100),
					new SqlParameter("@LawyerID", SqlDbType.VarChar,50),
					new SqlParameter("@ArchiveID", SqlDbType.VarChar,36),
					new SqlParameter("@IsArchive", SqlDbType.Int,4),
					new SqlParameter("@CreatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@CreatedDate", SqlDbType.DateTime)};
			parameters[0].Value = model.FileID;
			parameters[1].Value = model.FileName;
			parameters[2].Value = model.FileNote;
			parameters[3].Value = model.FileURL;
			parameters[4].Value = model.LawyerID;
			parameters[5].Value = model.ArchiveID;
			parameters[6].Value = model.IsArchive;
			parameters[7].Value = model.CreatedBy;
			parameters[8].Value = model.CreatedDate;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Lawyer.Model.FileInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update FileInfo set ");
			strSql.Append("FileName=@FileName,");
			strSql.Append("FileNote=@FileNote,");
			strSql.Append("FileURL=@FileURL,");
			strSql.Append("LawyerID=@LawyerID,");
			strSql.Append("ArchiveID=@ArchiveID,");
			strSql.Append("IsArchive=@IsArchive,");
			strSql.Append("CreatedBy=@CreatedBy,");
			strSql.Append("CreatedDate=@CreatedDate");
			strSql.Append(" where FileID=@FileID ");
			SqlParameter[] parameters = {
					new SqlParameter("@FileName", SqlDbType.VarChar,50),
					new SqlParameter("@FileNote", SqlDbType.VarChar,1000),
					new SqlParameter("@FileURL", SqlDbType.VarChar,100),
					new SqlParameter("@LawyerID", SqlDbType.VarChar,50),
					new SqlParameter("@ArchiveID", SqlDbType.VarChar,36),
					new SqlParameter("@IsArchive", SqlDbType.Int,4),
					new SqlParameter("@CreatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@CreatedDate", SqlDbType.DateTime),
					new SqlParameter("@FileID", SqlDbType.VarChar,36)};
			parameters[0].Value = model.FileName;
			parameters[1].Value = model.FileNote;
			parameters[2].Value = model.FileURL;
			parameters[3].Value = model.LawyerID;
			parameters[4].Value = model.ArchiveID;
			parameters[5].Value = model.IsArchive;
			parameters[6].Value = model.CreatedBy;
			parameters[7].Value = model.CreatedDate;
			parameters[8].Value = model.FileID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string FileID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from FileInfo ");
			strSql.Append(" where FileID=@FileID ");
			SqlParameter[] parameters = {
					new SqlParameter("@FileID", SqlDbType.VarChar,36)};
			parameters[0].Value = FileID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string FileIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from FileInfo ");
			strSql.Append(" where FileID in ("+FileIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Lawyer.Model.FileInfo GetModel(string FileID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 FileID,FileName,FileNote,FileURL,LawyerID,ArchiveID,IsArchive,CreatedBy,CreatedDate from FileInfo ");
			strSql.Append(" where FileID=@FileID ");
			SqlParameter[] parameters = {
					new SqlParameter("@FileID", SqlDbType.VarChar,36)};
			parameters[0].Value = FileID;

			Lawyer.Model.FileInfo model=new Lawyer.Model.FileInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["FileID"]!=null && ds.Tables[0].Rows[0]["FileID"].ToString()!="")
				{
					model.FileID=ds.Tables[0].Rows[0]["FileID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["FileName"]!=null && ds.Tables[0].Rows[0]["FileName"].ToString()!="")
				{
					model.FileName=ds.Tables[0].Rows[0]["FileName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["FileNote"]!=null && ds.Tables[0].Rows[0]["FileNote"].ToString()!="")
				{
					model.FileNote=ds.Tables[0].Rows[0]["FileNote"].ToString();
				}
				if(ds.Tables[0].Rows[0]["FileURL"]!=null && ds.Tables[0].Rows[0]["FileURL"].ToString()!="")
				{
					model.FileURL=ds.Tables[0].Rows[0]["FileURL"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LawyerID"]!=null && ds.Tables[0].Rows[0]["LawyerID"].ToString()!="")
				{
					model.LawyerID=ds.Tables[0].Rows[0]["LawyerID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ArchiveID"]!=null && ds.Tables[0].Rows[0]["ArchiveID"].ToString()!="")
				{
					model.ArchiveID=ds.Tables[0].Rows[0]["ArchiveID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["IsArchive"]!=null && ds.Tables[0].Rows[0]["IsArchive"].ToString()!="")
				{
					model.IsArchive=int.Parse(ds.Tables[0].Rows[0]["IsArchive"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CreatedBy"]!=null && ds.Tables[0].Rows[0]["CreatedBy"].ToString()!="")
				{
					model.CreatedBy=ds.Tables[0].Rows[0]["CreatedBy"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreatedDate"]!=null && ds.Tables[0].Rows[0]["CreatedDate"].ToString()!="")
				{
					model.CreatedDate=DateTime.Parse(ds.Tables[0].Rows[0]["CreatedDate"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select FileID,FileName,FileNote,FileURL,LawyerID,ArchiveID,IsArchive,CreatedBy,CreatedDate ");
			strSql.Append(" FROM FileInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

        public DataSet GetPathList(string FileIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FileURL from FileInfo ");
            if (FileIDlist.Length != 0)
            {
                strSql.Append(" where FileID in (" + FileIDlist + ")");
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" FileID,FileName,FileNote,FileURL,LawyerID,ArchiveID,IsArchive,CreatedBy,CreatedDate ");
			strSql.Append(" FROM FileInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "FileInfo";
			parameters[1].Value = "FileID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

